package com.mammoth.Bodybuilding.respository;

import java.util.List;

import javax.persistence.Table;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.mammoth.Bodybuilding.entity.SysMenu;

/**
 * 
 * 
 * @title : IMenuRepository.java
 * @description : 系统菜单 数据仓库
 * @company : com.mammoth.Bodybuilding.respository
 * @project Mammoth
 * @author xingzhaojun
 * @date 2018年4月27日上午10:06:11
 */
@Repository
@Table(name = "SYS_MENU")
@Qualifier("menuRespository")
public interface IMenuRepository extends JpaRepository<SysMenu, Long> {
	
	@Query("select m from SysMenu m where m.fid=:fid order by m.sortNum DESC")
	List<SysMenu> findAllByFid(@Param("fid") Long fid);
	
	@Query("select m from SysMenu m where m.menuPath=:path")
	SysMenu findMenuByPath(@Param("path") String path);
	
	@Query("select m from SysMenu m where m.fid=:fid")
	List<SysMenu> findFMenu(@Param("fid") Long fid);
	
	@Query("select m from SysMenu m where m.menuName like CONCAT('%',:name,'%') and m.menuPath like CONCAT('%',:path,'%') order by sortNum desc")
	Page<SysMenu> findMenuByParam(Pageable pageable,@Param("name") String name,@Param("path")String path);

	@Query("select m from SysMenu m where m.menuName like CONCAT('%',:name,'%') and m.menuPath like CONCAT('%',:path,'%') and m.fid=:fid order by sortNum desc")
	Page<SysMenu> findMenuByParam(Pageable pageable,@Param("name") String name,@Param("path")String path,@Param("fid") Long fid);
	
	@Query("select m.menuName from SysMenu m where m.fid=:fid")
	String findByFid(@Param("fid") Long fid);
	
	
}
